import React from 'react';
import { Scene } from 'phaser';
import { Socket } from 'socket.io-client';
import { EventBus } from '@/EventBus';

export class Boot extends Scene {

    constructor() {
        super('Boot');
    }

    init() {
        // console.log('Boot-init')
    }

    preload() {
        // console.log('Boot-preload')

        this.load.setPath('assets');
        this.load.image('wallImg', 'walls.png')
        this.load.tilemapTiledJSON('wallMap', 'walls.json')

        const myGraphics = this.add.graphics()
        myGraphics.fillStyle(0x0d0c0c)
        myGraphics.fillCircle(20, 20, 20)
        myGraphics.generateTexture('ball', 40, 40)
        myGraphics.clear()

        myGraphics.beginPath()
        myGraphics.fillStyle(0x0d0c0c)
        myGraphics.moveTo(0, 10)
        myGraphics.lineTo(20, 10)
        myGraphics.lineTo(10, 0)
        myGraphics.closePath()
        myGraphics.fill()
        myGraphics.generateTexture('direction', 20, 10)
        myGraphics.clear()

        myGraphics.destroy()
    }

    create() {
        // console.log('Boot-create')
        EventBus.on('toMainScene', (socketRef: React.MutableRefObject<Socket | null>,players:any) => {
            // console.log('前往MainScene')
            this.scene.start('MainScene', { socketRef,players })
        })

    }
}
